﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class EventTriggerListener : UnityEngine.EventSystems.EventTrigger
{
    public delegate void VoidDelegate(GameObject go);

    #region 事件
    public event VoidDelegate OnPointerClickEvent;
    public event VoidDelegate OnInitializePotentialDragEvent;
    public event VoidDelegate OnEndDragEvent;
    public event VoidDelegate OnDragEvent;
    public event VoidDelegate OnDropEvent;
    public event VoidDelegate OnDeselectEvent;
    public event VoidDelegate OnCancelEvent;
    public event VoidDelegate OnBeginDragEvent;
    public event VoidDelegate OnMoveEvent;
    public event VoidDelegate OnPointerDownEvent;
    public event VoidDelegate OnPointerEnterEvent;
    public event VoidDelegate OnPointerExitEvent;
    public event VoidDelegate OnPointerUpEvent;
    public event VoidDelegate OnScrollEvent;
    public event VoidDelegate OnSelectEvent;
    public event VoidDelegate OnSubmitEvent;
    public event VoidDelegate OnUpdateSelectedEvent;
    #endregion



    static public EventTriggerListener Get(GameObject go)
    {
        EventTriggerListener listener = go.GetComponent<EventTriggerListener>();

        if (listener == null)
            listener = go.AddComponent<EventTriggerListener>();

        return listener;
    }

    public override void OnPointerClick(PointerEventData eventData)
    {
        if (OnPointerClickEvent != null)
            OnPointerClickEvent(gameObject);
    }


    public override void OnBeginDrag(PointerEventData eventData)
    {
        if (OnBeginDragEvent != null)
            OnBeginDragEvent(gameObject);
    }

    public override void OnCancel(BaseEventData eventData)
    {
        if (OnCancelEvent != null)
            OnCancelEvent(gameObject);
    }

    public override void OnDeselect(BaseEventData eventData)
    {
        if (OnDeselectEvent != null)
            OnDeselectEvent(gameObject);
    }

    public override void OnDrag(PointerEventData eventData)
    {
        if (OnDragEvent != null)
            OnDragEvent(gameObject);
    }

    public override void OnDrop(PointerEventData eventData)
    {
        if (OnDropEvent != null)
            OnDropEvent(gameObject);
    }

    public override void OnEndDrag(PointerEventData eventData)
    {
        if (OnEndDragEvent != null)
            OnEndDragEvent(gameObject);
    }

    public override void OnInitializePotentialDrag(PointerEventData eventData)
    {
        if (OnInitializePotentialDragEvent != null)
            OnInitializePotentialDragEvent(gameObject);
    }

    public override void OnMove(AxisEventData eventData)
    {
        if (OnMoveEvent != null)
            OnMoveEvent(gameObject);
    }


    public override void OnPointerDown(PointerEventData eventData)
    {
        if (OnPointerDownEvent != null)
            OnPointerDownEvent(gameObject);
    }

    public override void OnPointerEnter(PointerEventData eventData)
    {
        if (OnPointerEnterEvent != null)
            OnPointerEnterEvent(gameObject);
    }

    public override void OnPointerExit(PointerEventData eventData)
    {
        if (OnPointerExitEvent != null)
            OnPointerExitEvent(gameObject);
    }


    public override void OnPointerUp(PointerEventData eventData)
    {
        if (OnPointerUpEvent != null)
            OnPointerUpEvent(gameObject);
    }

    public override void OnScroll(PointerEventData eventData)
    {
        if (OnScrollEvent != null)
            OnScrollEvent(gameObject);

    }

    public override void OnSelect(BaseEventData eventData)
    {
        if (OnSelectEvent != null)
            OnSelectEvent(gameObject);

    }

    public override void OnSubmit(BaseEventData eventData)
    {
        if (OnSubmitEvent != null)
            OnSubmitEvent(gameObject);
    }

    public override void OnUpdateSelected(BaseEventData eventData)
    {
        if (OnUpdateSelectedEvent != null)
            OnUpdateSelectedEvent(gameObject);
    }
}
